package com.sww.test.mode;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
/**
*
*  @author author
*/
public class persons implements Serializable {

    private static final long serialVersionUID = 1525940230614L;


    /**
    * 
    * isNullAble:1
    */
    private String account;

    /**
    * 
    * isNullAble:1
    */
    private String password;


    public void setAccount(String account){
        this.account = account;
    }

    public String getAccount(){
        return this.account;
    }

    public void setPassword(String password){
        this.password = password;
    }

    public String getPassword(){
        return this.password;
    }
    @Override
    public String toString() {
        return "persons{" +
                "account='" + account + '\'' +
                "password='" + password + '\'' +
            '}';
    }

    public static QueryBuilder QueryBuild(){
        return new QueryBuilder();
    }

    public static class QueryBuilder extends persons{
        /**
        * 需要返回的列
        */
        private Map<String,Object> fetchFields;

        public Map<String,Object> getFetchFields(){
            return this.fetchFields;
        }

        private List<String> accountList;


        private List<String> fuzzyAccount;

        public List<String> getFuzzyAccount(){
            return this.fuzzyAccount;
        }

        private List<String> rightFuzzyAccount;

        public List<String> getRightFuzzyAccount(){
            return this.rightFuzzyAccount;
        }
        private List<String> passwordList;


        private List<String> fuzzyPassword;

        public List<String> getFuzzyPassword(){
            return this.fuzzyPassword;
        }

        private List<String> rightFuzzyPassword;

        public List<String> getRightFuzzyPassword(){
            return this.rightFuzzyPassword;
        }
        private QueryBuilder (){
            this.fetchFields = new HashMap<>();
        }


        public QueryBuilder fuzzyAccount (List<String> fuzzyAccount){
            this.fuzzyAccount = fuzzyAccount;
            return this;
        }

        public QueryBuilder fuzzyAccount (String ... fuzzyAccount){
            if (fuzzyAccount != null){
                List<String> list = new ArrayList<>();
                for (String item : fuzzyAccount){
                    if (item != null){
                        list.add(item);
                    }
                }
                this.fuzzyAccount = list;
            }
            return this;
        }

        public QueryBuilder rightFuzzyAccount (List<String> rightFuzzyAccount){
            this.rightFuzzyAccount = rightFuzzyAccount;
            return this;
        }

        public QueryBuilder rightFuzzyAccount (String ... rightFuzzyAccount){
            if (rightFuzzyAccount != null){
                List<String> list = new ArrayList<>();
                for (String item : rightFuzzyAccount){
                    if (item != null){
                        list.add(item);
                    }
                }
                this.rightFuzzyAccount = list;
            }
            return this;
        }

        public QueryBuilder account(String account){
            setAccount(account);
            return this;
        }

        public QueryBuilder accountList(String ... account){
            if (account != null){
                List<String> list = new ArrayList<>();
                for (String item : account){
                    if (item != null){
                        list.add(item);
                    }
                }
                this.accountList = list;
            }

            return this;
        }

        public QueryBuilder accountList(List<String> account){
            this.accountList = account;
            return this;
        }

        public QueryBuilder fetchAccount(){
            setFetchFields("fetchFields","account");
            return this;
        }

        public QueryBuilder excludeAccount(){
            setFetchFields("excludeFields","account");
            return this;
        }



        public QueryBuilder fuzzyPassword (List<String> fuzzyPassword){
            this.fuzzyPassword = fuzzyPassword;
            return this;
        }

        public QueryBuilder fuzzyPassword (String ... fuzzyPassword){
            if (fuzzyPassword != null){
                List<String> list = new ArrayList<>();
                for (String item : fuzzyPassword){
                    if (item != null){
                        list.add(item);
                    }
                }
                this.fuzzyPassword = list;
            }
            return this;
        }

        public QueryBuilder rightFuzzyPassword (List<String> rightFuzzyPassword){
            this.rightFuzzyPassword = rightFuzzyPassword;
            return this;
        }

        public QueryBuilder rightFuzzyPassword (String ... rightFuzzyPassword){
            if (rightFuzzyPassword != null){
                List<String> list = new ArrayList<>();
                for (String item : rightFuzzyPassword){
                    if (item != null){
                        list.add(item);
                    }
                }
                this.rightFuzzyPassword = list;
            }
            return this;
        }

        public QueryBuilder password(String password){
            setPassword(password);
            return this;
        }

        public QueryBuilder passwordList(String ... password){
            if (password != null){
                List<String> list = new ArrayList<>();
                for (String item : password){
                    if (item != null){
                        list.add(item);
                    }
                }
                this.passwordList = list;
            }

            return this;
        }

        public QueryBuilder passwordList(List<String> password){
            this.passwordList = password;
            return this;
        }

        public QueryBuilder fetchPassword(){
            setFetchFields("fetchFields","password");
            return this;
        }

        public QueryBuilder excludePassword(){
            setFetchFields("excludeFields","password");
            return this;
        }

        public QueryBuilder fetchAll(){
            this.fetchFields.put("AllFields",true);
            return this;
        }

        public QueryBuilder addField(String ... fields){
            List<String> list = new ArrayList<>();
            if (fields != null){
                for (String field : fields){
                    list.add(field);
                }
            }
            this.fetchFields.put("otherFields",list);
            return this;
        }
        @SuppressWarnings("unchecked")
        private void setFetchFields(String key,String val){
            Map<String,Boolean> fields= (Map<String, Boolean>) this.fetchFields.get(key);
            if (fields == null){
                fields = new HashMap<>();
            }
            fields.put(val,true);
            this.fetchFields.put(key,fields);
        }

        public persons build(){
            return this;
        }
    }

}
